//
//  CYRewardInfoListTVC.m
//  CreditAddressBookEE
//
//  Created by LE on 16/2/16.
//  Copyright © 2016年 Lee. All rights reserved.
//

#import "CYRewardInfoListTVC.h"
#import "CYRewardInfoCell.h"
#import "UITableViewCell+Category.h"
#import "CYSimpleLoanM.h"
#import "CYRewardSearchCell.h"
#import "CYApplyRewardVC.h"
#import "LEPresentingAnimatorTool.h"
#import "CYCreditTool.h"

@interface CYRewardInfoListTVC ()

@end

@implementation CYRewardInfoListTVC

- (void)setList:(NSArray *)list {
    _list = list;
    [self.tableView reloadData];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.backgroundColor = [UIColor clearColor];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}

#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.list.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    CYSimpleLoanM *model = self.list[indexPath.row];
    if (self.type == CYRewardTypeSearch) {
        CYRewardSearchCell *cell = [CYRewardSearchCell cellWithTableView:tableView];
        cell.licencePlateLabel.text = model.carNumberH;
        cell.moneyLabel.text = model.rewardMoney;
        cell.companyName.text = model.companyNameH;
        cell.companyPhone.text = model.companyPhoneH;
        cell.timeLabel.text = [CYCreditTool timewithLongLongValue:model.limitTime.longLongValue formatter:@"yyyy-MM-dd"];
        cell.name.text = model.nameH;
        cell.phone.text = model.phoneH;
        cell.idCard.text = model.certificateNumberH;
        cell.applyBtn.tag = indexPath.row;
        [cell.applyBtn addTarget:self action:@selector(applyBtn:) forControlEvents:UIControlEventTouchUpInside];
        return cell;
    } else {
        CYRewardInfoCell *cell = [CYRewardInfoCell cellWithTableView:tableView];
        cell.cphLabel.text = model.carNumberH;
        cell.xsjeLabel.text = model.rewardMoney;
        cell.companyLabel.text = model.companyNameH;
        cell.companyPhoneLabel.text = model.companyPhoneH;
        return cell;
    }
}

- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 70;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (self.type == CYRewardTypeSearch) {
        return 180;
    }
    return 70;
}
/*!
 *  @brief  申请悬赏金额
 */
- (void)applyBtn:(UIButton *)btn {
    CYSimpleLoanM *model = self.list[btn.tag];
    CYApplyRewardVC *apply = [[CYApplyRewardVC alloc] init];
    apply.model = model;
    [LEPresentingAnimatorTool presentingAnimatorWithController:apply showIn:self completion:nil];
}

@end
